<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="出发地" prop="stationName">
        <el-autocomplete
          class="inline-input"
          clearable
          v-model="queryParams.stationName"
          :fetch-suggestions="StationQuerySearch"
          placeholder="请输入车站名称搜索"
          size="small"
          :trigger-on-focus="false"
          @select="handleSelect"
        ></el-autocomplete>
      </el-form-item>
      <el-form-item label="目的地" prop="targetId">
        <el-input
          v-model="queryParams.targetId"
          placeholder="请输入目的地"
          clearable
          style="width: 160px"
          size="small"
        />
      </el-form-item>
      <el-form-item label="发车日期" prop="busDate">
        <el-date-picker
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          v-model="queryParams.busDate"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <!--<el-form-item label="发车时间" prop="orderStatus">
        <el-select
          v-model="queryParams.time"
          placeholder=""
          clearable
          size="small"
          style="width: 110px"
        >
          <el-option
            v-for="dict in statusList"
            :key="dict.code"
            :label="dict.msg"
            :value="dict.code"
          />
        </el-select>
      </el-form-item>-->

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          v-hasPermi="['station:trainNumberList:query']"
          @click="handleQuery"
          >查询</el-button
        >
        <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        > -->
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="序号" align="center" type="index" width="50" />
      <el-table-column label="车次" align="center" prop="busnum" />
      <el-table-column label="类型" align="center" prop="iswater">
        <template slot-scope="scope">
          <p v-if="list[scope.$index].iswater == 0">固定班</p>
          <p v-if="list[scope.$index].iswater == 1">流水班</p>
        </template>
      </el-table-column>
      <el-table-column label="出发地" align="center" prop="stationName" />
      <el-table-column label="目的地" align="center" prop="targetName" />
      <el-table-column label="终点站" align="center" prop="terminalName" />
      <el-table-column label="发车日期" align="center" prop="startDate" />
      <el-table-column label="发车时间" align="center" prop="startTime" />
      <el-table-column label="里程(km)" align="center" prop="mileage" />
      <el-table-column label="车型" align="center" prop="busType" />
      <el-table-column label="票价(元)" align="center" prop="price" />
      <el-table-column label="余票数" align="center" prop="restTickets" />
    </el-table>

    <!-- <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageIndex"
      :limit.sync="queryParams.pageSize"
      @pagination="handleQuery"
    /> -->
  </div>
</template>

<script>
// import { list, delLogininfor, cleanLogininfor } from "@/api/system/logininfor";
import utils from "../../js/index";
import { BusNum } from "@/api/station/trainNumberList";
import { querystations, querytargets } from "@/api/order/refundList";
export default {
  name: "TrainNumberList",
  data() {
    return {
      statusList: [
        { msg: "全部", code: 1000 },
        { msg: "00:00~6:00", code: 100 },
        { msg: "6:00~8:00", code: 0 },
        { msg: "8:00~10:00", code: 1 },
        { msg: "10:00~12:00", code: 2 },
        { msg: "12:00~14:00", code: 3 },
        { msg: "14:00~16:00", code: 6 },
        { msg: "16:00~18:00", code: 7 },
        { msg: "18:00~20:00", code: 8 },
        { msg: "20:00~24:00", code: 9 }
      ],
      radio: "true",
      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: ""
      },
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 状态数据字典
      statusOptions: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageIndex: 1,
        pageSize: 10,
        stationName: "",
        busDate: "",
        targetId: ""
        // time:"全部",
      },
      //车站列表
      stationArry: [],
      stationList: []
    };
  },
  created() {
    // 获取所有出发站
    this.getStationList();
  },
  methods: {
    // 查询车次列表
    handleQuery() {
      if (this.queryParams.busDate == "") {
        this.$notify.error({
          title: "错误",
          message: "请选择日期"
        });
      } else if (this.queryParams.stationName == "") {
        this.$notify.error({
          title: "错误",
          message: "请输入出发站"
        });
      } else {
        BusNum(this.queryParams).then(response => {
          this.total = response.data.total;
          this.list = response.data.rows;
        });
      }
    },
    // 车站名模糊查询
    StationQuerySearch(queryString, cb) {
      var restaurantsStation = this.stationArry;
      var results = queryString
        ? restaurantsStation.filter(this.StationCreateFilter(queryString))
        : restaurantsStation;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    StationCreateFilter(queryString) {
      return v => {
        return v.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0;
      };
    },
    // 获取所有车站名
    getStationList() {
      querystations().then(res => {
        if (res.code == 200) {
          this.stationList = res.data;
          var arr = [];
          res.data.forEach(item => {
            arr.push({ value: item.stationName });
          });
          this.stationArry = arr;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    createFilter(queryString) {
      return restaurant => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        );
      };
    },
    handleSelect(val) {
      // console.log(val);
      var data = this.stationList.filter(function(item) {
        return item.stationName == val.value;
      });
      // console.log(data[0].globalCode);
      querytargets({ globalCode: data[0].globalCode }).then(response => {
        // console.log(response);
      });
    },
    /** 重置按钮操作 */
    resetQuery() {}
  }
};
</script>

<style scoped>
.refItem {
  line-height: 50px;
}
#refDiv {
  font-size: 15px;
}
</style>
